package com.bigger.controller;

import com.bigger.dto.CreateOrderDTO;
import com.bigger.entity.Order;
import com.bigger.result.Result;
import com.bigger.service.OrderService;
import com.bigger.vo.OrderDetailVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/order")
public class OrderController {
    @Autowired
    private OrderService orderService;
    @PostMapping("/create")
    public Result<String> createOrder(@RequestBody CreateOrderDTO createOrderDTOList) {
        orderService.createOrder(createOrderDTOList);
        return Result.success("下单完成");
    }
    @GetMapping("/get")
    public Result<List<Order>> get(){ //TODO 以后需要修改为传参
        List<Order> orders = orderService.get();
        return Result.success(orders);
    }
    @GetMapping("/get/{id}")
    public Result<OrderDetailVO> getById(@PathVariable("id") Long id){
        OrderDetailVO order = orderService.getById(id);
        return Result.success(order);
    }
    @PutMapping("/chargebacks")
    public Result<String> chargebacks(Long id){
        orderService.chargebacks(id);
        return Result.success("退单完成");
    }

}
